package cn.wolfcode.trip.app.web.interceptor;

import cn.wolfcode.trip.app.util.UserContext;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class CheckLoginInterceptor extends HandlerInterceptorAdapter {
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
            throws Exception {
        if (UserContext.getCurrentUser() == null) {
            //没有登录,回到登录界面,不要放行
            response.sendRedirect("/login.html");
            return false;
        }
        return true; //放行
    }
}
